<?php
class ManagersController extends AppController {

	var $name = 'Managers';
	var $layout='manager';
	function admin_index() {
		$this->Manager->recursive = 0;
		$this->set('managers', $this->paginate());
	}

	function admin_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid manager', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('manager', $this->Manager->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->Manager->create();
			if ($this->Manager->save($this->data)) {
				$this->Session->setFlash(__('The manager has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The manager could not be saved. Please, try again.', true));
			}
		}
		$accounts = $this->Manager->Account->find('list');
		$profiles = $this->Manager->Profile->find('list');
		$organizations = $this->Manager->Organization->find('list');
		$this->set(compact('accounts', 'profiles', 'organizations'));
	}

	function admin_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid manager', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Manager->save($this->data)) {
				$this->Session->setFlash(__('The manager has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The manager could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Manager->read(null, $id);
		}
		$accounts = $this->Manager->Account->find('list');
		$profiles = $this->Manager->Profile->find('list');
		$organizations = $this->Manager->Organization->find('list');
		$this->set(compact('accounts', 'profiles', 'organizations'));
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for manager', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Manager->delete($id)) {
			$this->Session->setFlash(__('Manager deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Manager was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
	/**
	 * @author tuan, do van
	 */
	function index (){
		$this->redirect('home');
	}
	function home (){
		$this->set ('action','Home');
	}
	function list_teacher (){
		$this->set ('action','List_Teacher');
	}
	function add_teacher (){
		
	}
	function edit_teacher (){
		
	}
	function delete_teacher (){
		
	}
}
